import Vue from 'vue'
import Router from 'vue-router'
import index from '@/page/index'

Vue.use(Router)


/**
 * 获取动态路由组件
 * @param componentName 文件位置
 * **/
const _loadComponent = (componentName) => {
  // 首页，
  return () =>
      import (`@/page/${componentName}`)
}

/**
 * 获取路由配置
 * @param pathName dirNameIndex restParams  文件位置、 文件名称，其它则解构参数
 * **/
const _getRouterPath = (pathName, dirName, restParams) => (Object.assign({}, {
  path: pathName,
  name: dirName,
  component: _loadComponent(pathName, dirName)
}, typeof restParams === 'string' ? { meta: { title: restParams } } : restParams))


export default new Router({
  mode:'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: index,
      redirect:'/Home/index',
      children:[
       
        _getRouterPath('Home/index','首页'),
        _getRouterPath('UserCenter/index','个人中心')
      ]
    }
  ]
})
